<template>
	<view>
		<stop isBack>
			<view slot="content">故障信息</view>
		</stop>
		<view class="bdtso bdbso mart3">
			 <stab :names="['基本信息','附件图片','维修情况','用料情况']" @change="tabSelect"></stab>
		</view>
		<view class="bcf pad2" v-show="TabCur == 0">
			<view class="list-style-2 flrc martb2">
				<view class="flex1">故障设备</view>
			</view>
			<!-- 显示选择的设备 -->
			<view class="flrc pad5 bdso bc13 mart3" @tap="goto('/pages/machine/machine_info?id=' + machineId)"  v-if="isbool(machineId)">
				<machine-item class="w100" :value="machineId" :itemId.sycn="machineId"  v-if="isbool(machineId)"></machine-item>
				<view class="fs14"><text class="fa fa-angle-right c12"></text></view>
			</view>
			<view class="list-style-2 flrc martb2">
				<view class="flex1">故障信息</view>
			</view>
			<view>
				<view class="flrc bdbda pad2">
					<view>故障单号：</view>
					<view class="flex1 tar">{{en.sn}}</view>
					<view class="cu-btn sm line-blue round marl2" @tap="copy(en.sn)">复制</view>
				</view>
				<view class="flrc bdbda pad2">
					<view>故障描述：</view>
					<view class="flex1 tar">{{en.info}}</view>
				</view>
				<view class="flrc bdbda pad2">
					<view>故障状态：</view>
					<view class="flex1 tar">
						<view style="display: inline-block;">
							<status class="padlr2 round2" :item="en.status"></status>
						</view>
					</view>
				</view>
				<view class="flrc bdbda pad2">
					<view>紧急程度：</view>
					<view class="flex1 tar">{{isnull(en.emergency)?'未设置':en.emergency.name}}</view>
				</view>
				<view class="flrc bdbda pad2">
					<view>故障类别：</view>
					<view class="flex1 tar">{{isnull(en.category)?'':en.category.name}}</view>
				</view>
				<view class="flrc bdbda pad2">
					<view>联系人姓名：</view>
					<view class="flex1 tar">{{en.contactName}}</view>
				</view>
				<view class="flrc bdbda pad2">
					<view>联系人电话：</view>
					<view class="flex1 tar">{{en.contactPhone}}</view>
				</view>
				<view class="flrc bdbda pad2">
					<view>订单创建：</view>
					<view class="flex1 tar">{{datetime(en.createAt)}}</view>
				</view>
				<view class="flrc bdbda pad2">
					<view>问题发现：</view>
					<view class="flex1 tar">{{datetime(en.findAt)}}</view>
				</view>
				<view class="flrc bdbda pad2">
					<view>故障修复：</view>
					<view class="flex1 tar">{{datetime(en.fixAt)}}</view>
				</view>
				<view class="flrc bdbda pad2">
					<view>验收确认：</view>
					<view class="flex1 tar">{{datetime(en.confirmAt)}}</view>
				</view>
			</view>
		</view>
		<view class="bcf pad2" v-show="TabCur == 1">
			<view class="list-style-2 flrc martb2">
				<view class="flex1">附件图</view>
			</view>
			<view>
				<image @tap="viewPic(pic(item),pics(en.pic))" class="w100" :src="pic(item)"  mode="widthFix" 
				v-for="item,index in en.pic" :key="index"></image>
			</view>
		</view>
		<view class="bcf pad2" v-show="TabCur == 2">
		
			<view class="pad2 " >
				<!-- <view class="pad10 tac c12 bdda bc13">维修完成并已确认</view> -->
				<view class="shadow1 pos-r" v-for="item in fixOrders">
					<fix-order class="pad2" :item="item" :showAngle="false"></fix-order>
				</view>
			</view>
			
		</view>
		<view class="bcf pad3 bdtso" v-if="TabCur == 3">
			<view class="tac mar3 pad3 bdda" v-show="items.length == 0">暂无数据</view>
			<view v-for="item in items" class="bdso">
				<store-item class="w100 pad1" :item="item.item"></store-item>
				<view class="w100 bdtdo bc13 flrc pad2">
					<view>使用数量：</view>
					<view class="flex1 tar fwb">{{item.num}}</view>
				</view>
			</view>
		</view>
		<loading :loading="myIsLoading"></loading>
	</view>
</template>

<script>
	import machine from '../../templete/machine/machine_item.vue'
	import fixOrder from '../../templete/machine/machine_fix_order_item.vue'
	import StoreItem from '../../templete/store/store_item.vue'
	export default {
		components:{machineItem:machine,fixOrder,StoreItem},
		data() {
			return {
				TabCur:0,
				scrollLeft:0,
				id:'',
				machineId:0,
				en:{machine:{id:0}},
				comment:'',
				fixOrders:[],
				items:[]
			}
		},
		methods: {
			tabSelect(index){
				this.TabCur = index
			},
			getFixOrder(){
				this.$api.get('/api/machineFixOrders/',{
					_where:{
						eq:{'breakOrder.sn':this.en.sn}
					}
				},(res)=>{
					this.log(res.d)
					this.fixOrders = res.d
					// this.machineId = res.d.machine.id
					// this.clearLoading()
					//获取维修单
					
				})
			},
			
			getStoreItemList(){
				this.$api.get('/api/machineParts',{
					_where:{eq:{
						'formOrder.breakOrder.id':this.id
					}},
					_g:['store','machine']
				},res=>{
					this.items = res.d
				})
			}
		},
		onLoad(option) {
			this.id = option.id
			this.showLoading()
			this.$api.get('/api/machineBreaks/'+ this.id,{},(res)=>{
				this.log(res.d)
				this.en = res.d
				this.machineId = res.d.machine.id
				this.clearLoading()
				//获取维修单
				this.getFixOrder()
				this.getStoreItemList()
			})
		}
	}
</script>

<style>

</style>
